﻿/*---------------------------------------------------------------------*/
// fileName="FileCommon.cs" CompanyName="SureKAM"
// Copyright SureKAM (c). All right reserved.
/*---------------------------------------------------------------------*/

namespace SureKAM.BackUp.Notify.Common
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;

    /// <summary>
    /// 文件、文件夹处理工具类
    /// </summary>
    public class FileCommon
    {
        /// <summary>
        /// 统计文件夹相关大小信息(MB)
        /// </summary>
        public static long SummaryFilesSize(DirectoryInfo  directoryInfo)
        {
            long fileSize = 0;

            ////统计文件信息
            foreach (FileInfo singleFile in directoryInfo.GetFiles())
            {
                fileSize += singleFile.Length;
            }

            ////统计子文件夹信息
            foreach (DirectoryInfo singleFiles in directoryInfo.GetDirectories())
            {
                fileSize += SummaryFilesSize(singleFiles);
            }
            return fileSize;
        }
    }
}
